package com.lin.androidgame21;

import android.graphics.Bitmap;

import java.util.ArrayList;

/***

 *Create By LWL Write

 **/

public class NPC extends Sprite {
    private boolean isMove ;
    private int[] frameSequence1 ;
    private int[] frameSequence2 ;
    private int state ;
    private int count ;
    private int delay ;
    private ArrayList<Talk> talks ;


    NPC(Bitmap bitmap, int width, int height) {
        super(bitmap, width, height);
    }

    public void setMove(int[] frameSequence1,int[] frameSequence2,int speedX,int speedY){
        isMove = true ;
        this.frameSequence1 = frameSequence1;
        this.frameSequence2 = frameSequence2;
        setSpeedX(speedX);
        setSpeedY(speedY);

    }

    @Override
    public void logic() {
        if (delay++==3){
            delay = 0 ;
            if (isMove){
                if (count++<20){
                    if (state!=1){
                        state = 1 ;
                        setFrameSequence(frameSequence1);
                        setFrameSequenceIndex(0);
                    }else {
                        move(getSpeedX(),getSpeedY());
                        nextFrame();
                    }
                }else {
                    if (state!=2){
                        state =2 ;
                        setFrameSequence(frameSequence2);
                        setFrameSequenceIndex(0);
                    }else {
                        move(-getSpeedX(),-getSpeedY());
                        nextFrame();
                    }
                    if (count==40){
                        count = 0;
                    }
                }
            }else {
                nextFrame();
            }
        }
    }

    @Override
    public void outOfBounds() {
    }

    public ArrayList<Talk> getTalks() {
        return talks;
    }

    public void setTalks(ArrayList<Talk> talks) {
        this.talks = talks;
    }
}
